import request from "@/utils/request";

const ORDER_BASE_URL = "/api/v1/order";

const OrderAPI = {
  /** 获取订单主分页数据 */
  getPage(queryParams?: OrderPageQuery) {
    return request<any, PageResult<OrderPageVO[]>>({
      url: `${ORDER_BASE_URL}/page`,
      method: "get",
      params: queryParams,
    });
  },
  /**
   * 获取订单主表单数据
   *
   * @param id 订单主ID
   * @returns 订单主表单数据
   */
  getFormData(id: number) {
    return request<any, OrderForm>({
      url: `${ORDER_BASE_URL}/${id}/form`,
      method: "get",
    });
  },

  /**
   *  添加订单主
   *
   *  @param data 订单主表单数据
   */
  add(data: OrderForm) {
    return request({
      url: `${ORDER_BASE_URL}`,
      method: "post",
      data,
    });
  },

  /**
   * 更新订单主
   *
   * @param id 订单主ID
   * @param data 订单主表单数据
   */
  update(id: number, data: OrderForm) {
    return request({
      url: `${ORDER_BASE_URL}/${id}`,
      method: "put",
      data,
    });
  },

  /**
   * 批量删除订单主，多个以英文逗号(,)分割
   *
   * @param ids 订单主ID字符串，多个以英文逗号(,)分割
   */
  deleteByIds(ids: string) {
    return request({
      url: `${ORDER_BASE_URL}/${ids}`,
      method: "delete",
    });
  },

  getCartOrderFormByUser() {
    return request<any, OrderForm>({
      url: `${ORDER_BASE_URL}/getCartOrderFormByUser`,
      method: "get",
    });
  },
};

export default OrderAPI;

/** 订单主分页查询参数 */
export interface OrderPageQuery extends PageQuery {
  /** 订单号 */
  orderSn?: string;
  /** 用户ID */
  userId?: number;
  createTime?: [string, string];
  /** 状态 */
  status?: number;
}

/** 订单主表单对象 */
export interface OrderForm {
  id?: number;
  /** 订单号 */
  orderSn?: string;
  /** 用户ID */
  userId?: number;
  /** 订单总额 */
  totalAmount?: number;
  /** 状态 */
  status?: number;
}

/** 订单主分页对象 */
export interface OrderPageVO {
  id?: number;
  /** 订单号 */
  orderSn?: string;
  /** 用户ID */
  userId?: number;
  /** 订单总额 */
  totalAmount?: number;
  createTime?: Date;
  /** 状态 */
  status?: number;
}
